//
//  UIImage+Extension.swift
//  HHSwift
//
//  Created by 华宏 on 2019/1/28.
//  Copyright © 2019年 huahong. All rights reserved.
//

import Foundation

extension UIImage{
    
    
    /// 根据颜色生成图片
    ///
    /// - Parameters:
    ///   - color: 颜色
    ///   - size: 图片尺寸
    /// - Returns: UIImage
  static  func image(withColor color:UIColor,size:CGSize) -> UIImage? {
    
        if size.width <= 0 || size.height <= 0 {
            return nil
        }
    
        let render = UIGraphicsImageRenderer(size: size)
        return render.image(actions: { (context) in
            
            let path = UIBezierPath(roundedRect: CGRect(origin: CGPoint(), size: size), byRoundingCorners: UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue), cornerRadii: CGSize(width: 3, height: 3))
            
            color.set()
            path.fill()
            
        });
    }
    
    
}
